/*
 * Copyright 2013 NJUT  qixiaobo. All rights reserved.
 */
package com.fujitsu.nanjing.tieba.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fujitsu.nanjing.tieba.base.BaseService;
import com.fujitsu.nanjing.tieba.ibator.CoreTrashBox;
import com.fujitsu.nanjing.tieba.ibator.CoreTrashBoxCriteria;
import com.fujitsu.nanjing.tieba.ibator.CoreTrashBoxKey;
import com.fujitsu.nanjing.tieba.model.TrashBox;

/**
 * TrashBoxService.java
 * 
 * @author Administrator
 */
@Service
@Transactional
public class TrashBoxService
		extends
			BaseService<CoreTrashBox, CoreTrashBoxCriteria> {
	@Resource
	private TrashBox trashBox;

	/**
	 * 此方法只能查找根据topicid，并非是真正的主键，如有需要可以调用 {@link findByPrimaryKey}
	 **/
	@Override
	@Deprecated
	public CoreTrashBox findById(String id) {
		CoreTrashBoxKey key = new CoreTrashBoxKey();
		key.setTopicid(Integer.parseInt(id));
		key.setReplyid(0);
		return trashBox.selectByPrimaryKey(key);
	}

	@Override
	public CoreTrashBox insert(CoreTrashBox t) {
		trashBox.insertSelective(t);
		return t;
	}

	@Override
	public void update(CoreTrashBox t) {
		trashBox.updateByPrimaryKeySelective(t);

	}

	@Override
	public void delete(CoreTrashBox t) {

		CoreTrashBoxKey _key = new CoreTrashBoxKey();
		_key.setTopicid(t.getTopicid());
		_key.setReplyid(t.getReplyid());
		trashBox.deleteByPrimaryKey(_key);

	}
	public CoreTrashBox findByPrimaryKey(int topicId, int replyId) {
		CoreTrashBoxKey _key = new CoreTrashBoxKey();
		_key.setTopicid(topicId);
		_key.setReplyid(replyId);
		return trashBox.selectByPrimaryKey(_key);

	}

}
